import { createApp } from "vue";
import { createPinia } from 'pinia';
import App from './App.vue'
import './styles/index.css'
const app = createApp(App)
const pinia = createPinia()
app.use(pinia)
app.mount('#app')


// ts中 typeof 和keyof(keyof只有ts)
const obj = {a: 1, b: 2, c: 3, d: 4}
// js中typeof 获取数据类型
console.log(typeof obj)

// ts中typeof 获取对应的对象类型
type Obj = typeof obj
const a: Obj = {
    a: 3,
    b: 4,
    c: 4,
    d: 1
}
a
// type MyKey = 'a' | 'b' | 'c' | 'd'
// keyof 在ts 中获取对象类型的键 组成联合类型
type Key = keyof Obj
const key: Key = 'c'
key


/**
 * 类型编程
 * getVal(obj, key) {
 *  return obj[key]
 * } 
 */
function getVal<O extends object, K extends keyof O>(obj: O, key: K) {
    return obj[key]
}
const objA = {
    a: 1,
    b: 2,
}
const objB = {
    c: 3,
    d: 4
}

console.log(getVal(objA, 'a'));
console.log(getVal(objB, 'd'));



